<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2018/7/16 0016
  Time: 上午 10:54
   专区商品
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<html>
<head>
    <head>
        <title>Title</title>
        <script src="../../js/jquery-3.3.1.min.js" charset="utf-8"></script>
        <script src="../../js/cookie/jquery.cookie.js" charset="utf-8"></script>
        <script src="../../layui-v2.2.5/layui/layui.js" charset="utf-8"></script>
        <link rel="stylesheet" href="../../layui-v2.2.5/layui/css/layui.css" media="all">
    </head>
</head>
<body>
<br><br><br>
<button class="layui-btn" id="add"  onclick="specialCommodityInfo('${id}')">添加商品</button>
<a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right;margin-right: 100px"  href="javascript:location.replace(location.href);" title="刷新">
    <i class="layui-icon" style="line-height:30px">ဂ</i></a>

<div class="layui-form">
    <form class="layui-form" action="">
        <table class="layui-table">
            <thead>
            <tr>
                <th>名称</th>
                <th>价格</th>
                <th>logo</th>
                <th>销量</th>
                <th>浏览次数</th>

                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            <c:forEach items="${pageUtil.list}" var="rl">
                <tr>
                    <td>${rl.commodityName}</td>
                    <td>${rl.commodityMoney}</td>
                    <td>
                            <img src="${rl.commodityLogo}" style="width: 3rem;height: 3rem">
                    </td>
                    <td>${rl.commoditySales}</td>
                    <td>${rl.commodityBrowseCount}</td>
                    <td>
                        <button type="button" class="layui-btn layui-btn-danger" onclick="del('${rl.id}');">删除</button>
                    </td>
                </tr>
            </c:forEach>
            </tbody>
        </table>
    </form>



    <div id="page"></div>
    <script>

        layui.use(['laypage', 'layer'], function(){
            var laypage = layui.laypage
                ,layer = layui.layer;
            //完整功能
            laypage.render({
                elem: 'page'
                ,count: ${pageUtil.totalRows}
                ,layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']
                ,jump: function(obj){
                    console.log(obj);
                    //首次不执行
                    if(!first){
                        //do something
                        window.location.href="/shop/specialCommodity?page="+obj.curr+"&limit="+obj.limit+"&id=${id}";
                    }

                }
            });

        });


    </script>

</div>
<script>
    layui.use('layer', function(){
        var layer = layui.layer;
    });


    /*删除商品*/
    function del(id) {
        $.ajax({
            url:'/shop/delSpecialCommodity',
            type:'POST', //GET
            async:true,    //或false,是否异步
            data:{
                id:id,
            },
            timeout:5000,    //超时时间
            dataType:'json',    //返回的数据格式：json/xml/html/script/jsonp/text
            beforeSend:function(xhr){
                /*console.log(xhr)
                 console.log('发送前')*/
            },
            success:function(dataA){
                console.log(dataA);
                if (dataA.code=='000000'){
                        window.location.reload();
                    // 获得frame索引
                }else {
                    layer.msg("删除失败",{time:1000,icon: 5});
                }
            },
            error:function(xhr,textStatus){
                console.log('错误')
                console.log(xhr)
                console.log(textStatus)
            },
            complete:function(){
                //console.log('结束')
            }
        })
    }
    /*设置商品轮播图*/
    function slideshow(id){
        layer.open({
            type: 2,
            area: ['90%', '80%'],
            offset: '20px',
            shadeClose:true,
            title:'轮播图设置',
            content: '/shop/slideshow?commodityId='+id,
            end:function () {
                console.log("页面要刷新");
                window.location.reload();
            }
        });
    }
    /*设置商品信息*/
    function commodityMessage(id){
        layer.open({
            type: 2,
            area: ['30%', '80%'],
            offset: '20px',
            shadeClose:true,
            title:'商品信息设置',
            content: '/shop/commodityMessage?commodityId='+id,
            end:function () {
                console.log("页面要刷新");
                window.location.reload();
            }
        });
    }

    /**
     * 新增商品
     */
    function specialCommodityInfo(id){
        layer.open({
            type: 2,
            area: ['50%', '50%'],
            offset: '20px',
            shadeClose:true,
            title:'新增专区商品',
            content: '/shop/specialCommodityInfo?specialId='+id,
            end:function () {
                console.log("页面要刷新");
                window.location.reload();
            }
        });
    }

</script>
</body>
</html>
